﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LEDScreen;
namespace LED.Test
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
            this.Load += new EventHandler(Form2_Load);
        }

        void Form2_Load(object sender, EventArgs e)
        {
            Int32 dev=1;
            char[] host="192.168.0.101".ToCharArray();
            LEDAPI.LED_Query(dev, 1, "192.168.0.101", 6666);
            
        }
        /// <summary>
        /// 重载窗口的消息机制，抓取LEDSender.dll发来的消息
        /// </summary>
        /// <param name="m">消息</param>
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == LEDAPI.WM_LED_NOTIFY)
            {
                LEDAPI.TNotifyMessage msg = new LEDAPI.TNotifyMessage();
                string content = string.Empty;

                if (LEDAPI.LED_GetNotifyMessage(ref msg) != 0)
                {
                    switch (msg.Message)
                    {
                        case LEDAPI.LM_TX_COMPLETE:
                            content = "发送完成";
                            break;
                        case LEDAPI.LM_RESPOND:
                            switch (msg.Command)
                            {
                                case LEDAPI.PKC_QUERY:
                                    content = "查询状态成功";
                                    
                                    break;
                                case LEDAPI.PKC_GET_POWER:
                                    content = (msg.Status == LEDAPI.LED_POWER_ON) ? "电源已打开" : "电源已关闭";
                                    break;
                                case LEDAPI.PKC_SET_POWER:
                                    if (msg.Result == 99)
                                        content = "处于自动开关屏模式,不能进行电源操作!";
                                    else if (msg.Status == LEDAPI.LED_POWER_ON)
                                        content = "电源已打开";
                                    else if (msg.Status == LEDAPI.LED_POWER_OFF)
                                        content = "电源已关闭";
                                    break;
                                case LEDAPI.PKC_GET_BRIGHT:
                                    content = "显示屏亮度为:" + msg.Status;
                                    break;
                                case LEDAPI.PKC_SET_BRIGHT:
                                    content = "亮度调整完毕";
                                    break;
                                case LEDAPI.PKC_ADJUST_TIME:
                                    content = "时钟校正完成";
                                    break;
                            }
                            break;
                        case LEDAPI.LM_TIMEOUT:
                            content = "传送超时";
                            break;
                    }
                    OnLedResponse(content, msg);
                }
            }
            else
            {
                base.WndProc(ref m);    //如果不是鼠标移动或单击消息就调用基类的窗口过程进行处理
            }
        }
        private void OnLedResponse(string content, LEDAPI.TNotifyMessage msg)
        {
            try
            {
                switch (msg.Message)
                { 
                    default:
                        break;
                }
            }
            catch (Exception ex)
            { 
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Int32 dev = 1;
            LEDAPI.LED_Query(dev, 1, "192.168.0.101", 6666);
        }
    }
}
